while [ -e $HOME/my/src/hhistory/main.cpp ]; do
    if [ ! -e $HOME/my/bin/hhistory ]; then
        g++ $HOME/my/src/hhistory/main.cpp -g -o $HOME/my/bin/hhistory
        if [[ $? != 0 ]]; then
            echo "please install g++, cannot compile cpp"
            break
        fi
    fi

    __fzfcmd() {
      [ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "$FZF_TMUX_OPTS" ]; } &&
        echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
    }

    fzf-history-widget() {
        local selected num
        setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
        selected=( $($HOME/my/bin/hhistory $HOME/.zsh_history |
            FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
        local ret=$?
        if [ -n "$selected" ]; then
            num=$selected[1]
            if [ -n "$num" ]; then
                zle vi-fetch-history -n $num
            fi
        fi
        zle reset-prompt
        return $ret
    }
    if which fzf 1>/dev/null 2>&1 && fzf --version 1>/dev/null 2>&1; then
        zle     -N   fzf-history-widget
        bindkey '^R' fzf-history-widget
    fi
    break
done
